<?php
/**
 * @author spenceryg
 * @date 2023/4/20
 * @time 11:07 下午
 * @focus love & life
 */


namespace app\auto\controller;


use think\facade\View;

class ConfigClass extends \app\BaseController
{
    public function index()
    {
        $data = \app\auto\model\ConfigClass::order('sort asc, id asc')->select();
        View::assign('data', $data);
        return View::fetch();
    }


    public function add()
    {
        if(request()->isPost()){
            \app\auto\model\ConfigClass::create(input());
            return success();
        }else{
            $count = \app\auto\model\ConfigClass::count();
            View::assign('sort', ($count + 1)*10);
            return View::fetch();
        }

    }

    public function update()
    {
        if(request()->isPost()) {
            \app\auto\model\ConfigClass::update(input());
            return success();
        }else{
            $data = \app\auto\model\ConfigClass::find(input('id'));
            View::assign('r', $data);
            return View::fetch();
        }
    }

    public function delete()
    {
        \app\auto\model\ConfigClass::destroy(input('id'));
        return success();
    }

}
